<?php
/**
 * VBScript 语音播放测试
 */

echo "=== VBScript 语音播放测试 ===\n\n";

$voiceFile = __DIR__ . '/voice/checkin_success.mp3';

if (!file_exists($voiceFile)) {
    echo "语音文件不存在: {$voiceFile}\n";
    exit(1);
}

echo "语音文件: {$voiceFile}\n";
echo "文件大小: " . filesize($voiceFile) . " 字节\n\n";

$realPath = realpath($voiceFile);
echo "完整路径: {$realPath}\n\n";

// 创建 VBScript
$tempScript = sys_get_temp_dir() . '/play_voice_test.vbs';
$vbsCode = 'Set Sound = CreateObject("WMPlayer.OCX.7")' . "\r\n";
$vbsCode .= 'Sound.URL = "' . str_replace('\\', '\\\\', $realPath) . '"' . "\r\n";
$vbsCode .= 'Sound.Controls.play' . "\r\n";
$vbsCode .= 'WScript.Sleep 3000' . "\r\n";  // 等待3秒

file_put_contents($tempScript, $vbsCode);

echo "VBScript 文件: {$tempScript}\n";
echo "VBScript 内容:\n";
echo $vbsCode . "\n";

echo "开始播放...\n";
$command = 'cscript //nologo "' . $tempScript . '"';
echo "执行命令: {$command}\n\n";

exec($command, $output, $returnCode);

echo "返回码: {$returnCode}\n";
if (!empty($output)) {
    echo "输出:\n" . implode("\n", $output) . "\n";
}

@unlink($tempScript);

echo "\n如果听到声音，说明 VBScript 方法可用！\n";
echo "如果没有声音，请检查 Windows Media Player 是否可用。\n";

